package com.aretias.jkholdings.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.aretias.jkholdings.model.BoardParam;
import com.aretias.jkholdings.model.Category;
import com.aretias.jkholdings.service.BoardService;
import com.aretias.jkholdings.service.CategoryService;

@Controller
public class MenuController {
	
	@Autowired
	private CategoryService categoryService;
	@Autowired
	private BoardService boardService;
	
	@RequestMapping("/home")
	public ModelAndView home() {
		Category category = new Category();
		category.setParentCategoryId(0);
		List<Category> categoryList = categoryService.getChild(category);
		ModelAndView mav = new ModelAndView("home");
		mav.addObject("categoryList", categoryList);
		BoardParam param = new BoardParam();
		param.setBoardType("qna");
		mav.addObject("qnaList", boardService.getBoardList(param));
		param.setBoardType("notice");
		mav.addObject("noticeList", boardService.getBoardList(param));
		return mav;
	}
	
	@RequestMapping("/contactus")
	public ModelAndView contactUs() {
		Category category = new Category();
		category.setParentCategoryId(0);
		List<Category> categoryList = categoryService.getChild(category);
		ModelAndView mav = new ModelAndView("contactus");
		mav.addObject("categoryList", categoryList);
		return mav;
	}
	
	@RequestMapping("/admin")
	public String login() {
		return "login";
	}
}
